﻿<style type="text/css">
 </style>
<div class="mv-edit validate-area" style="margin-top:10px;">
    <div class="cont-top">
        <span>昵称</span>
        <input id="username" type="text" class="validate-elem" :value="bag.basis.info.username" validate="true" validate-message="请输入新昵称" placeholder="请输入新昵称">
    </div>
    <div class="cont-top">
        <span>个性签名</span>
        <input id="sign" type="text" class="validate-elem" :value="bag.basis.info.sign">
    </div>
    <div class="cont-top">
        <span style="height:45px;">隐私</span>
        <label><input id="ischatfriend" type="checkbox" class="validate-elem" :checked="bag.basis.info.ischatfriend" />拒绝陌生人消息</label>
    </div>
    <div class="cont-top">
        <span>性别</span>
        <select id="sexs" class="validate-elem" validate="true" validate-message="请选择性别">
            <option>请选择</option>
        </select>
    </div>
    <div class="cont-top">
        <span>职业</span>
        <select id="trade" class="validate-elem" validate="true" validate-message="请选择职业">
            <option>请选择</option>
        </select>
    </div>
    <div class="cont-top">
        <span>公司</span>
        <input id="company" type="text" class="validate-elem" :value="bag.basis.info.company">
    </div>
    <div class="cont-top">
        <span>学校</span>
        <input id="school" type="text" class="validate-elem" :value="bag.basis.info.school">
    </div>
    <div class="cont-top">
        <span>省</span>
        <select id="country" validate="true">
            <option>请选择</option>
        </select>
    </div>
    <div class="cont-top">
        <span>市</span>
        <select id="province" validate="true">
            <option>请选择</option>
        </select>
    </div>
    <div class="cont-top">
        <span>县</span>
        <select id="county" class="validate-elem" validate="true" validate-message="请选择地区">
            <option value="">请选择</option>
        </select>
    </div>
</div>
<div style="height:60px;"></div>

<script type="text/javascript">
    var pagedata = {
        request: {
            method: "VIEW_USER_USEREDIT_DATUM"
        },
        screen: {
            header_ok_display: true,
            header_display: true,
            header_title_name: "社交设置",
            header_exit_name: "返回",
            header_ok_name: '保存',
            header_exit_click: function () {
                mview.view.load('/views/User/setting.html')
            },
            header_ok_click: function () {
                //调用验证表单程序
                mview.view.form.validate("validate-area", function (data) {
                    mview.socket.send({
                        data: {
                            method: "USEREDIT_DATUM",
                            username: data.username,
                            sexs: data.sexs,
                            trade: data.trade,
                            sign: data.sign,
                            school: data.school,
                            company: data.company,
                            placeid: data.county,
                            ischatfriend: String(data.ischatfriend)
                        },
                        success: function (data) {
                            if (data.Code == 0) {
                                mview.control.tips("修改成功");
                                setTimeout(function () {
                                    mview.view.load("views/user/main.html");
                                }, 1500);
                            }
                            else {
                                mview.control.tips(data.Message);
                            }
                        }
                    });
                });
            },
            header_display: true,
            footer_choose: "user"
        },
        oncreate: function () {
            mview.custom.set_sexs(m.view.node("#sexs"), function () {
                m.view.node("#sexs").value(pagedata.data.bag.basis.info.sexs);
            });
            mview.custom.set_trade(m.view.node("#trade"), function () {
                m.view.node("#trade").value(pagedata.data.bag.basis.info.trade);
            });

            mview.custom.set_place(m.view.node("#country"), '001', function () {
                var placeid = pagedata.data.bag.basis.info.placeid;
                m.view.node("#country").on("change", function () {
                    mview.custom.set_place(m.view.node("#province"), m.view.node("#country").value(), function () { });
                });
                m.view.node("#province").on("change", function () {
                    mview.custom.set_place(m.view.node("#county"), m.view.node("#province").value(), function () { });
                });
                //填充初始数据
                var country_val = placeid.length >= 5 ? placeid.substring(0, 5) : "";
                var province_val = placeid.length >= 7 ? placeid.substring(0, 7) : "";
                var county_val = placeid.length >= 9 ? placeid.substring(0, 9) : "";
                if (country_val != "") {
                    m.view.node("#country").value(country_val);
                    mview.custom.set_place(m.view.node("#province"), country_val, function () {
                        if (province_val != "") {
                            m.view.node("#province").value(province_val);
                            if (county_val != "") {
                                mview.custom.set_place(m.view.node("#county"), province_val, function () {
                                    m.view.node("#county").value(county_val);
                                });
                            }
                        }
                    });
                }
            });
        },
        data: {

        },
        methods: {
            send_sms: function (event) {
                var elm = event.target;
                mview.custom.sms_only_send(elm);
            }
        }
    }
    mview.view.chlid.init(pagedata);
</script>